/*
 *说明：会话日志 首页脚本
 *
 *@author liuxun 2012-04-06
*/

var opeForm;
var selectedSessionLogId;	// 选择的会话日志记录ID
var opeForm;
var sessionLogGrid;
var cmdLogGrid;


$(function(){
	opeForm = $('#opeForm');
	$("#tabs").tabs({}); 

	sessionLogGrid=$('#sessionLogTable').datagrid({
		columns:[[
		          
		    {title:'机构名称  ',field:'ORG_NAME',align:'center',width:150},
		    
		    {title:'用户姓名 ',field:'USR_NAME',align:'center',width:80},
		    
            {title:'节点名称',field:'NODE_DECODE',align:'center',width:120},
            
            {title:'节点IP',field:'NODE_IP',align:'center',width:100},
		    
		    {title:'资源名称',field:'RSC_NAME',align:'center',width:100},
		    
		    {title:'账号名',field:'RSC_ACC_ID',align:'center',width:80},

            {title:'协议',field:'PRO_NAME',align:'center',width:60},
            
		    {title:'开始时间',field:'BEGIN_TIME',align:'center',width:120},
		          
		    {title:'结束时间',field:'END_TIME',align:'center',width:120},
            
            {title:'管理IP',field:'MANAGE_IP',align:'center',width:100},
 
            {title:'服务IP',field:'SERVICE_IP',align:'center',width:100},

			{title:'操作',field:'operation',align:'center',width:80,
	        	formatter:function(value,rec){
	        		if(rec.END_TIME == null || rec.END_TIME == ''){
	        			 return '';	   
	        		}else{
	             		var s = '<a style="cursor:pointer; color:blue" onclick=\'showPlayback("' + rec.SESSION_LOG_ID + '")\'>回放</a>';
		        	    return s;
	        		}
	        	}
		    }
        ]],
		pagination:true,
		singleSelect: true,
		onClickRow: function(rowIndex, rowData) {
			var selectedSessionLogId = rowData.SESSION_LOG_ID;
			queryCmdLogOperation(selectedSessionLogId);
	    }
	});
	
	cmdLogGrid=$('#cmdLogTable').datagrid({
		columns:[[

            {title:'开始时间',field:'BEGIN_TIME',align:'center',width:200},

            {title:'命令',field:'CMD',align:'center',width:450}
        ]],
		pagination:true,
		singleSelect: false
	});	
	
	queryOperation();

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
	$('#addBtn').click(addOperation);
	$('#editBtn').click(editOperation);
	$('#deleteBtn').click(deleteOperation);
	$('#genReportBtnSession').click(genReporOperation);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=sessionLogGrid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = opeForm.serializeObject();
	sessionLogGrid.datagrid("options").pageNumber = 1;
	sessionLogGrid.datagrid({
		url: 'E_SESSION_LOG!queryList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//查询命令日志操作
function queryCmdLogOperation(selectedSessionLogId){
	var params = opeForm.serializeObject();
	cmdLogGrid.datagrid("options").pageNumber = 1;
	cmdLogGrid.datagrid({
		url: 'E_CMD_LOG!queryList.do?modelMap.session_log_id=' + selectedSessionLogId
	});
}

//显示回放页面
function showPlayback(key) {
	var url = 'E_SESSION_LOG!showPlayback.do?model.key=' + key;
	openWin(url,'pop','','','','','yes'); 
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//查看明细
function showInfo(key) {
	var url = 'E_SESSION_LOG!showInfo.do?model.key=' + key;
	openWin(url,'pop','A0','1000','800','','yes'); 
}

//添加会话日志
function addOperation(){  
	var url = 'E_SESSION_LOG!showAdd.do';
	openWin(url,'pop');
}

//编辑会话日志
function editOperation(){  
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  

	if (rows.length > 1) {
		showInfoWin('只能选择一条记录');
      	return; 
	}

	var url = 'E_SESSION_LOG!showEdit.do?model.key=' + rows[0].key;
	openWin(url,'pop');
}   

//删除会话日志
function deleteOperation() {
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中要删除的记录!');	
		return;
	}

	var ids = [];
	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].key);
	}
	var params = $ .param({'id' : ids}, true);

	$ .messager.confirm('提示信息', '您确定要删除选定的' + rows.length + '条记录吗?', function(result){
		if(result){
			$ .ajax({
				url: 'E_SESSION_LOG!doDelete.do',
				data: params,
				type: 'post',
				success: function(data){
				    showInfoWin('操作成功!');
					afterOK();
				}
			});
		}	
	});
}

//选择资源
function select_c_rsc() {
	var action = "C_RSC!showSelect.do?model.rsc_status=01";
	var row = showModalWin(action,'A2');
	
	if (row) {
		$('#rsc_name').val(row.rsc_name);
	}
}

//生成会话日志报表
function genReporOperation(){
	opeForm.attr('action', 'E_SESSION_LOG!genSessionLogReport.do');
	opeForm.submit();
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}